package com.ccc.demoboot.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccc.demoboot.dao.MaterialMapper;
import com.ccc.demoboot.pojo.Material;
import com.ccc.demoboot.service.MaterialService;

/**
 * @Author wz
 * @Date 2024/6/4 9:02
 * @PackageName:com.ccc.demoboot.service
 * @ClassName: MaterialServiceImpl
*/
@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService{

    @Override
    public List<Map<String,Object>> selectDuo() {
        return this.baseMapper.selectDuo();
    }

    @Override
    public Map<String, Object> upSelectId(Integer id) {
        return this.baseMapper.upSelectId(id);

    }

    @Override
    public List<Map<String, Object>> searchSelectId(String materialname) {
        return this.baseMapper.searchSelectId(materialname);
    }

    @Override
    public boolean upQuantity(int materialid,int warehouseid,int areaid,int shelves, int content) {
        Material material = new Material();
        QueryWrapper<Material> materialQueryWrapper = new QueryWrapper<>();
        material.setMaterialid(materialid);
        materialQueryWrapper.setEntity(material);
        Material one = this.baseMapper.selectOne(materialQueryWrapper);
        if(one!=null){
            content+=one.getQuantity();
            material.setQuantity(content);
            int i = this.baseMapper.updateById(material);
            if(i>0){
                return true;
            }
            return false;
        }
        material.setWarehouseid(warehouseid);
        material.setAreaid(areaid);
        material.setShelves(shelves);
        material.setQuantity(content);
        int i = this.baseMapper.insert(material);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override

    public List<Material> zhuSelectQ() {

        return this.baseMapper.zhuSelectQ();
    }

    @Override
    public List<Material> zhuSelectName() {

        return this.baseMapper.zhuSelectName();
    }

    @Override
    public List<Map<String, Object>> selectAllMaterial(QueryWrapper materialQueryWrapper) {
        return this.baseMapper.selectAllMaterial(materialQueryWrapper);

    }

    @Override
    public Map<String, Object> selectOne(Integer id) {
        return this.baseMapper.selectOne(id);
    }


}
